<template>
	<view :class="['dhcc-base', themeName]" class="dhcc-container">
		<!-- 轮播 -->
		<view class="dhcc-home-page-banner-wrap">
			<swiper class="dhcc-home-page-swiper" circular indicator-dots indicator-color="rgba(255,255,255,0.3)" indicator-active-color="#ffffff">
				<swiper-item v-for="(item, index) in 2" :key="index">
					<view class="dhcc-home-page-swiper-item">
						<image :src="'/static/images/gbxt' + (index + 1) + '.png'" mode="aspectFill" />
					</view>
				</swiper-item>
			</swiper>
		</view>
		<uni-notice-bar show-icon scrollable text="欢迎使用！江西省保健信息管理系统。" />
		<!-- 模板内容 -->
		<view class="dhcc-home-page-content-wrap">
			<view class="dhcc-home-page-title">保健服务</view>
			<view class="dhcc-home-page-content">
				<view v-for="(item, index) in cellList" :key="index" class="dhcc-home-page-template"
					@click="listAll(index)">
					<view class="dhcc-home-page-template-img">
						<image class="dhcc-home-page-icon" :src="item.icon" />
					</view>
					<view>
						<view class="dhcc-home-page-template-title">{{ item.title }}</view>
						<view class="dhcc-home-page-template-info">{{ item.info }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tokenCache from '@/request/token/tokenCache'
	export default {
		data() {
			return {
				personName: '',
				personSex: '',
				cellList: [{
						title: '健康信息',
						icon: '/static/images/icon/icon1.png'
					},
					/* {
						title: '对象列表',
						icon: '/static/images/icon/icon2.png'
					}, */
					{
						title: '体检记录',
						icon: '/static/images/icon/icon2.png'
					},
					{
						title: '健康咨询',
						icon: '/static/images/icon/icon3.png'
					},
					{
						title: '健康教育',
						icon: '/static/images/icon/icon4.png'
					},
					{
						title: '健康资讯',
						icon: '/static/images/icon/icon5.png'
					},
					{
						title: '医院查询',
						icon: '/static/images/icon/icon1.png'
					},
					{
						title: '医生查询',
						icon: '/static/images/icon/icon2.png'
					},
					{
						title: '体检预约记录',
						icon: '/static/images/icon/icon3.png'
					}
				],
				current: 0
			}
		},
		methods: {
			switchTab(index) {
				this.current = index
			},
			listAll(index) {
				let url = ''
				switch (this.cellList[index].title) {
					case '健康信息':
						url = '/subPackages/pages/personHealth/personHealthAdd'
						break
					case '对象列表':
						url = '/subPackages/pages/personHealth/personHealthList'
						break
					case '体检记录':
						url = '/subPackages/pages/bodyCheck/bodyCheckList'
						break
					case '健康咨询':
						url = '/subPackages/pages/healthAsk/healthAsk'
						break
					case '健康教育':
						url = '/subPackages/pages/personHealth/personHealth'
						break
					case '健康资讯':
						// 调用 uni-app 跨平台跳转API
						uni.navigateToMiniProgram({
						  appId: 'wx811d61e1f61155a4', // 腾讯医典小程序的 AppID（需替换为实际值）
						  //path: 'pages/detail/detail?id=xxx', // 可选：指定跳转的具体页面路径
						  success(res) {
						    console.log('跳转成功', res)
						  },
						  fail(err) {
						    console.error('跳转失败', err)
						    // 失败处理：如提示用户手动搜索
						    /* uni.showToast({
						      title: '跳转失败，请手动搜索「腾讯医典」',
						      icon: 'none'
						    }) */
						  }
						})
						/* url = '/subPackages/pages/healthEdu/healthEdu' */
						break
					case '医院查询':
						url = '/subPackages/pages/personHealth/hospitalList'
						break
					case '医生查询':
						url = '/subPackages/pages/doctor/doctorList'
						break
					case '体检预约记录':
						url = '/subPackages/pages/bodyCheckBookingList/bodyCheckBookingList'
						break
					default:
						break
				}
				uni.navigateTo({
					url: url
				})
			},
		},
		onLoad() {
			// 设置小程序标题
			uni.setNavigationBarTitle({
				title: '江西省保健信息管理系统'
			})
			const allTokenCache = tokenCache.get()
			if (allTokenCache !== '') {
				
			} else {
				uni.showModal({
					title: '提示',
					content: '登陆已过期，请重新登录',
					showCancel: false,
					confirmColor: '#0566A8',
					confirmText: '去登陆',
					success: function(res) {
						if (res.confirm) {
							uni.reLaunch({
								url: '/pages/loginPage/loginPage'
							})
						}
					},
					fail: function(res) {

					}
				})
			}

		}
	}
</script>

<style>
	.dhcc-base {
		padding-bottom: 150rpx;
	}

	.dhcc-home-page-navbar {
		font-size: var(--font-size-title-second);
		color: var(--dhcc-other-color);
		background: var(--dhcc-con-back);
		position: relative;
		line-height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 var(--padding-medium);
	}

	.dhcc-home-page-navbar-title {
		width: 50%;
		font-weight: bold;
	}

	.dhcc-home-page-navbar-right-wrap {}

	.dhcc-home-page-navbar-right-icon {
		margin-left: var(--padding-large);
		font-size: 46rpx;
	}

	.dhcc-tabbar-wrap {
		padding-bottom: 50rpx;
		background-color: var(--dhcc-con-back);
	}

	.dhcc-home-page-banner-wrap {
		padding: 0 var(--padding-medium) var(--padding-medium);
	}

	.dhcc-home-page-swiper {
		height: 300rpx;
		border-radius: var(--border-radius-large);
		overflow: hidden;
	}

	.dhcc-home-page-swiper-item {
		display: block;
		height: 300rpx;
		line-height: 300rpx;
		text-align: center;
		color: white;
	}
	
	/* 针对轮播图的图片设置 */
	.dhcc-home-page-swiper-item image {
	  width: 100%;
	  height: 100%;
	  border-radius: var(--border-radius-large); /* 与容器圆角一致 */
	  display: block; /* 消除可能的间隙 */
	}

	.banner-bg-red {
		background-color: red;
	}

	.banner-bg-green {
		background-color: green;
	}

	.banner-bg-blue {
		background-color: blue;
	}

	.dhcc-home-page-content-wrap {}

	.dhcc-home-page-title {
		padding: 0 var(--padding-medium);
		font-size: var(--font-size-title-normal);
		font-weight: bold;
	}

	.dhcc-home-page-content {
		margin: var(--padding-medium);
		padding: var(--padding-medium) 0;
		background-color: var(--dhcc-con-back);
		border-radius: var(--border-radius-large);
		display: flex;
		align-items: center;
		flex-wrap: wrap;
	}

	.dhcc-home-page-icon {
		width: 100%;
		height: 100%;
	}

	.dhcc-home-page-content2 {
		background-color: transparent;
		padding: 0;
	}

	.dhcc-home-page-template {
		width: 47%;
		background-color: var(--dhcc-con-back);
		border-radius: var(--border-radius-large);
		padding: var(--padding-medium);
		box-sizing: border-box;
		margin: 0 3% 3% 0;
		display: flex;
		align-self: center;
	}

	.dhcc-home-page-template-img {
		width: 70rpx;
		height: 70rpx;
		margin-right: var(--padding-small);
	}

	.dhcc-home-page-template-title {
		font-size: var(--font-size-text-normal);
	}

	.dhcc-home-page-template-info {
		font-size: var(--font-size-text-small);
		color: var(--dhcc-text-color);
		margin-top: 4rpx;
	}
</style>